<?php
namespace App\Services;

use App\Criteria\DatatableSearchCriteriaCriteria;
/**
 * services 基类
 */
class BaseServices
{
	
	/**
	 * datatable 数据
	 * @author 晚黎
	 * @date   2020-01-13
	 * @param  [type]     $repository [description]
	 * @return [type]                 [description]
	 */
	public function getDatatableList($repository)
	{
		// 开始条数
        $start = request('start', 0);
        // 每页显示数目
        $length = request('length', 10);
        
        // 排序
        $order['name'] = request('columns.' .request('order.0.column', 0) . '.name');
        $order['dir'] = request('order.0.dir','asc');


		$repository->pushCriteria(DatatableSearchCriteriaCriteria::class);

		$count = $repository->count();
		$lists = $repository->orderBy($order['name'], $order['dir'])->offset($start)->limit($length)->get();

		return [
			'draw' => request('draw', 1), // datatables请求次数
			'recordsTotal' => $count,
			'recordsFiltered' => $count,
			'data' => $lists,
		];
	}
	
}